#include<Engine.h>
using namespace Advanced2D;
#include"Mario.h"
#include"Gach.h"

Texture g_background;
Texture g_texturMario;
Texture g_brick;

Sprite* background;
Mario* mario;
Gach* gach;


bool game_preload(){
	g_engine->setAppTitle("GameMario");
	g_engine->setFullScreen(false);
	g_engine->setScreenWidth(800);
	g_engine->setScreenHeight(600);
	g_engine->setColorDepth(32);
	
	g_camera->setSizeWorld(1600,600);
	g_camera->setSizeView(800,600);	

	return true;
}

bool game_init(){
	if(!g_background.load("..\\Data\\Image\\background.jpg")) return false;
	if(!g_texturMario.load("..\\Data\\Image\\PlayLon.png")) return false;
	if(!g_brick.load("..\\Data\\Image\\ExplodeGach.png")) return false;			

	background = new Sprite();	
	background->setImage(&g_background);	
	background->setPosition(0, 600);

	gach = new Gach();
	gach->setImage(&g_brick);	
	gach->setPosition(100, 100);	

	mario = new Mario();	
	mario->setObjectType(100);
	mario->setPosition(10, 200);
	mario->setVelocity(8,0);	
	mario->setImage(&g_texturMario);
	mario->setSize(47,90);
	mario->setAnimcolumns(5);
	mario->setTotalFrame(10);		
	mario->setAnimdir(0);
	mario->setFrameTime(16);
	mario->setMoveTime(16);	
	
	g_engine->addEntity(background);
	g_engine->addEntity(gach);
	g_engine->addEntity(mario);
	
	g_camera->Init(mario);

	return true;
}

void game_update(){			
}

void game_entityUpdate(Entity* entity){
}

void game_render2D(){	
	g_camera->Update();
}

void game_entityRender(Entity* entity){	
}

void game_end(){	
	delete mario;
	delete background;
	delete gach;
}

void game_keyPress(int key){
	switch(key){
	case DIK_LEFT:
		mario->keyLeft();			
		break;
	case DIK_RIGHT:
		mario->keyRight();		
		break;
	case DIK_DOWN:
		mario->keyUp();			
		break;	
	}			
}

void game_keyRelease(int key){
	switch(key){
	case DIK_ESCAPE: 
		g_engine->ExitGame();
		break;
	default:
		mario->keyRelease();				
		break;
	}	
}